﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace Sitecore.Models
{
    public class Client : IAssignable
    {
        [Required]
        [StringLength(50, MinimumLength = 1)]
        public string FirstName { get; set; }

        [Required]
        [StringLength(50, MinimumLength = 1)]
        public string LastName { get; set; }

        [Required]
        [StringLength(50, MinimumLength = 5)]
        public string Phone { get; set; }

        [DisplayFormat(ConvertEmptyStringToNull = false)]
        public string Adress { get; set; }

        [DisplayFormat(ConvertEmptyStringToNull = false)]
        public string Email { get; set; }

        public void AssignTo(object domain)
        {
            if (domain is DataProject.Client)
            {
                DataProject.Client client = domain as DataProject.Client;
                client.FName = this.FirstName;
                client.LName = this.LastName;
                client.Adress = this.Adress;
                client.Email = this.Email;
                client.Phone = this.Phone;
            }
            else throw new NotSupportedException("not valid domain type");
        }

        public static Client FromDbModel(DataProject.Client client)
        {
            Client _thisClient = new Client();
            _thisClient.FirstName = client.FName;
            _thisClient.LastName = client.LName;
            _thisClient.Adress = client.Adress;
            _thisClient.Email = client.Email;
            _thisClient.Phone = client.Phone;
            return _thisClient;
        }
    }
}